-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Data Classes to Model API Responses #203
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
/gcbrun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Jorge! Looking great.
Adds: - A Node dataclass which models an individual node (with dcid, name, etc) - A NodeGroup dataclass which represents a list of Node objects - An Arcs dataclass, which represents arcs (with a label and containing NodeGroups) - A Properties dataclass which represents a list of Properties
Adds: - An Observation dataclass which models an individual observation (date, value) - An OrderedFacets dataclass which models the 'ordered facets' of observations - A Variable dataclass which represents a variable data (grouped by entity) - A Facet class which represents the metadata for a facet
Adds: - A candidate dataclass to model candidates in the response (with dcid and dominanType) - An Entity dataclass to model entities with their resolution candidates
Adds: - A Cell dataclass to model a single cell in a row - A Row modelling a row with cells.
Adds tests for node, observation, resolve and sparql models.
58b9e57
to
1a53857
Compare
Note:
Previous PR in the stack: #202
Next PR in the stack #204
This PR implements dataclasses to model API responses from all endpoints. These data classes represent various entities in the Data Commons knowledge graph. Dan's comments on the design document provide more details about the rationale.
Data Classes
datacommons_client/models/node.py
: AddedNode
,NodeGroup
,Arcs
, andProperties
data classes to represent nodes, groups of nodes, arcs, and properties in the Data Commons knowledge graph.datacommons_client/models/observation.py
: AddedObservation
,OrderedFacets
,Variable
, andFacet
data classes to represent observations, ordered facets, variables, and facets in the Data Commons knowledge graph.datacommons_client/models/resolve.py
: AddedCandidate
andEntity
data classes to represent candidates and entities in the resolution response.datacommons_client/models/sparql.py
: AddedCell
andRow
data classes to represent cells and rows in a SPARQL query response. Note that the sparql endpoint does not (currently) work for custom instances.Unit Tests
In general, the tests for these classes are just making sure that the objects (especially objects that incorporate other objects) are built consistently and correctly. We avoid testing any basic python functionality.
datacommons_client/tests/models/test_node_models.py
: Added unit tests for theNode
,NodeGroup
,Arcs
, andProperties
classes, testing theirfrom_json
methods with both complete and partial data.datacommons_client/tests/models/test_observation_models.py
: Added unit tests for theObservation
,OrderedFacets
,Variable
, andFacet
classes, testing theirfrom_json
methods with various data scenarios.datacommons_client/tests/models/test_resolve_models.py
: Added unit tests for theCandidate
andEntity
classes, testing theirfrom_json
methods with complete, partial, and empty data.datacommons_client/tests/models/test_sparql_models.py
: Added unit tests for theCell
andRow
classes, testing theirfrom_json
methods with different types of cell data, including nested empty cells.